<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="lufylegend-1.10.0.js"></script>
</head>

<body>
<div id="mylegend">loading...</div>
<script>
init(0,"mylegend",800,600,main);
var backlayer,resultlayer,clicklayer,loadinglayer,seltbitmap,enemybitmap,selftextall,selftextwin,selftextloss,selftextdraw,win=0,loss=0,draw=0;
var imglist={};
var imgdata=new Array(
	{name:"title",path:"title.png"},
	{name:"jiandao",path:"jiandao.png"},
	{name:"shitou",path:"shitou.png"},
	{name:"bu",path:"bu.png"}
);
var showList=new Array();
var checklist=[[0,1,-1],[-1,0,1],[1,-1,0]];
function main(){
	LGlobal.setDebug(true);
	backlayer=new LSprite();
	addChild(backlayer);
	loadinglayer=new LoadingSample3();
	backlayer.addChild(loadinglayer);
	LLoadManage.load(
		imgdata,
		function(progress){
			loadinglayer.setProgress(progress);
		},
		function(result){
			imglist=result;
			backlayer.removeChild(loadinglayer);
			loadinglayer=null;
			gameInit();	
		}
	);
}
function gameInit(){
	showList.push(new LBitmapData(imglist["shitou"]));
	showList.push(new LBitmapData(imglist["jiandao"]));
	showList.push(new LBitmapData(imglist["bu"]));
	//添加游戏背景界面
	backlayer.graphics.drawRect(10,"#008800",[0,0,LGlobal.width,LGlobal.height],true,"#000000");
	//显示游戏标题
	var titlebitmap=new LBitmap(new LBitmapData(imglist["title"]));
	titlebitmap.x=(LGlobal.width-titlebitmap.width)/2;
	titlebitmap.y=10;
	backlayer.addChild(titlebitmap);
	//玩家方出拳图片
	seltbitmap=new LBitmap(showList[0]);
	seltbitmap.x=400-seltbitmap.width-50;
	seltbitmap.y=130;
	backlayer.addChild(seltbitmap);
	//电脑方出拳图片
	enemybitmap=new LBitmap(showList[0]);
	enemybitmap.x=400+50;
	enemybitmap.y=130;
	backlayer.addChild(enemybitmap);
	//玩家电脑名称设定
	var nametext;
	nametext=new LTextField();
	nametext.text="玩家";
	nametext.weight="bolder";
	nametext.color="#ffffff";
	nametext.size=24;
	nametext.x=seltbitmap.x+(seltbitmap.width-nametext.getWidth())/2;
	nametext.y=95;
	backlayer.addChild(nametext);
	nametext=new LTextField();
	nametext.text="电脑";
	nametext.weight="bolder";
	nametext.color="#ffffff";
	nametext.size=24;
	nametext.x=enemybitmap.x+(enemybitmap.width-nametext.getWidth())/2;
	nametext.y=95;
	backlayer.addChild(nametext);
	//结果显示层初始化
	initResultLayer();
	//操作层初始化
	initClickLayer();
}
function initResultLayer(){
	resultlayer=new LSprite();
	resultlayer.graphics.drawRect(4,"#ff8800",[0,0,150,110],true,"#ffffff");
	resultlayer.x=10;
	resultlayer.y=100;
	backlayer.addChild(resultlayer);	
	selftextall=new LTextField();
	selftextall.text="猜拳次数：0";
	selftextall.weight="bolder";
	selftextall.x=10;
	selftextall.y=20;
	resultlayer.addChild(selftextall);
	selftextwin=new LTextField();
	selftextwin.text="胜利次数：0";
	selftextwin.weight="bolder";
	selftextwin.x=10;
	selftextwin.y=40;
	resultlayer.addChild(selftextwin);
	selftextloss=new LTextField();
	selftextloss.text="失败次数：0";
	selftextloss.weight="bolder";
	selftextloss.x=10;
	selftextloss.y=60;
	resultlayer.addChild(selftextloss);
	selftextdraw=new LTextField();
	selftextdraw.text="平局次数：0";
	selftextdraw.weight="bolder";
	selftextdraw.x=10;
	selftextdraw.y=80;
	resultlayer.addChild(selftextdraw);
	
}
function initClickLayer(){
	clicklayer=new LSprite();
	clicklayer.graphics.drawRect(4,"#ff8800",[0,0,300,110],true,"#ffffff");
	clicklayer.x=258;
	clicklayer.y=275;
	backlayer.addChild(clicklayer);
	var msgtext=new LTextField();
	msgtext.text="请出拳：";
	msgtext.weight="bolder";
	msgtext.x=10;
	msgtext.y=10;
	clicklayer.addChild(msgtext);
	var shitou=getButton("shitou");
	shitou.x=30;
	shitou.y=35;
	clicklayer.addChild(shitou);
	shitou.addEventListener(LMouseEvent.MOUSE_UP,onclick);
	var jiandao=getButton("jiandao");
	jiandao.x=115;
	jiandao.y=35;
	clicklayer.addChild(jiandao);
	jiandao.addEventListener(LMouseEvent.MOUSE_UP,onclick);
	var bu=getButton("bu");
	bu.x=200;
	bu.y=35;
	clicklayer.addChild(bu);
	bu.addEventListener(LMouseEvent.MOUSE_UP,onclick);
	clicklayer.x=250;
	clicklayer.y=275;
	backlayer.addChild(clicklayer);
}
function onclick(event,display){
	var selfvalue,enemyvalue;
	if(display.name=="shitou"){
		selfvalue=0;
	}else if(display.name=="jiandao"){
		selfvalue=1;
	}else if(display.name=="bu"){
		selfvalue=2;	
	}
	enemyvalue=Math.floor(Math.random()*3);
	seltbitmap.bitmapData=showList[selfvalue];
	enemybitmap.bitmapData=showList[enemyvalue];
	var result=checklist[selfvalue][enemyvalue];
	if(result==-1){
		loss+=1;
	}else if(result==1){
		win+=1;
	}else{
		draw+=1;	
	}
	selftextwin.text="胜利次数：" + win;
	selftextloss.text="失败次数：" + loss;
	selftextdraw.text="平局次数：" + draw;
	selftextall.text="猜拳次数："+(win+loss+draw);
}
function getButton(value){
	var btnUp=new LBitmap(new LBitmapData(imglist[value]));
	btnUp.scaleX=0.5;
	btnUp.scaleY=0.5;
	var btnOver=new LBitmap(new LBitmapData(imglist[value]));
	btnOver.scaleX=0.5;
	btnOver.scaleY=0.5;
	btnOver.x=2;
	btnOver.y=2;
	var btn=new LButton(btnUp,btnOver);
	btn.name=value;
	return btn;
}
</script>
</body>
</html>
